from django.contrib import admin
from .models import *
from django import forms


# Register your models here.
@admin.register(SchoolOrganizationInfo, SchoolHonorInfo, SchoolContactInfo,
                PartyStaffInfo, PartyTeacherInfo,
                NewsCenterInfo, AnnounceCenterInfo, MenuCenterInfo,
                BeautifulBlackboardInfo, BeautifulSportInfo, BeautifulActivityInfo,
                HomeQuestionnaireInfo, HomeFeedbackInfo)
# @admin.register(MenuCenterInfo)
class SchoolModelAdmin(admin.ModelAdmin):
    ordering = ('-id', )
    list_display = ['id', 'article_title', 'article_type', 'article_date', 'article_preview']

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        query_type = None
        if request.path_info.find('SchoolOrganizationInfo'.lower()) > 0:
            query_type = '组织机构'
        elif request.path_info.find('SchoolHonorInfo'.lower()) > 0:
            query_type = '学校荣誉'
        elif request.path_info.find('SchoolContactInfo'.lower()) > 0:
            query_type = '联系我们'
        elif request.path_info.find('PartyStaffInfo'.lower()) > 0:
            query_type = '教职工党建'
        elif request.path_info.find('PartyTeacherInfo'.lower()) > 0:
            query_type = '师生党建'
        elif request.path_info.find('NewsCenterInfo'.lower()) > 0:
            query_type = '校内新闻'
        elif request.path_info.find('AnnounceCenterInfo'.lower()) > 0:
            query_type = '学校公示'
        elif request.path_info.find('MenuCenterInfo'.lower()) > 0:
            query_type = '每日菜谱'
        elif request.path_info.find('BeautifulBlackboardInfo'.lower()) > 0:
            query_type = '黑板报'
        elif request.path_info.find('BeautifulSportInfo'.lower()) > 0:
            query_type = '运动会'
        elif request.path_info.find('BeautifulActivityInfo'.lower()) > 0:
            query_type = '集体活动'
        elif request.path_info.find('HomeQuestionnaireInfo'.lower()) > 0:
            query_type = '问卷调查'
        elif request.path_info.find('HomeFeedbackInfo'.lower()) > 0:
            query_type = '意见反馈'
        return qs.filter(article_type=query_type)




